clear all
set	more off

cd "~/Dropbox/ors_quality_R01"
use "data/KDG/know_do_gap.dta", clear


/* Controls 
Years of experience: ps_b11
Provider age: ps_b06
Number of patients per day: ps_b37
Number of diarrhea cases per week: ps_b39
Competitive market: comp_cat
Sell medicine/attached pharmacy: ps_dispense
*/

recode rec_anti (1 = 0) (0 =1), gen(no_anti)

global controls  i.prov_type ps_b11 ps_b06 ps_b37 ps_b39 i.comp_cat ps_dispense

**************
*** Pooled ***
**************

*eliminating know gap (effect of knowing X share that do not know)
	
	*ORS
	sum know_ors
	local know_gap_ors= 1- r(mean)
	reg rec_ors i.know_ors $controls severe, robust 
	
	local know_change_ors= _b[1.know_ors]*`know_gap_ors'
	
	*Anti
	sum know_anti
	local  know_gap_anti = 1-r(mean)
	reg rec_anti i.know_anti $controls severe, robust

	local know_change_anti= _b[1.know_anti]*`know_gap_anti'
	
	di `know_change_anti'
	
*eliminating know do gap (size of gap for those that know X share that know)
	
	*ORS
	sum rec_ors if know_ors
	local know_do_gap_ors = 1-r(mean)
	
	sum know_ors
	
	local know_do_change_ors = `know_do_gap_ors' *r(mean)
	
	*Anti
	sum no_anti if know_anti & sp_type!=1
	local know_do_gap_anti = 1-r(mean)
	
	sum know_anti 
	
	local know_do_change_anti = -`know_do_gap_anti' *r(mean)
	
	di `know_do_change_anti'
	
	*adjusted numbers
	foreach stat in  know_change_ors know_do_change_ors know_change_anti know_do_change_anti{
		local `stat' = string(``stat'', "%10.3f")  
	}
	
	mata: tab_ors = ( "Pooled" , "`know_change_ors'" , "`know_do_change_ors'" )
	mata: tab_anti = ( "Pooled" , "`know_change_anti'" , "`know_do_change_anti'" )

	

***************
*** By Type ***
***************

gen MBBS = prov_type==1
gen RMP = prov_type==2
gen AYUSH = prov_type==3
gen Pharmacy = prov_type==4

foreach i in MBBS RMP AYUSH Pharmacy{
	preserve
	
	keep if `i'==1
	
*eliminating know gap (effect of knowing X share that do not know)
	
	*ORS
	sum know_ors
	local know_gap_ors= 1- r(mean)
	reg rec_ors i.know_ors $controls severe, robust 
	
	local know_change_ors= _b[1.know_ors]*`know_gap_ors'
	
	*Anti
	sum know_anti
	local  know_gap_anti = 1-r(mean)
	reg rec_anti i.know_anti $controls severe, robust

	local know_change_anti= _b[1.know_anti]*`know_gap_anti'
	
*eliminating know do gap (size of gap for those that know X share that know)
	
	*ORS
	sum rec_ors if know_ors
	local know_do_gap_ors = 1-r(mean)
	
	sum know_ors
	
	local know_do_change_ors = `know_do_gap_ors' *r(mean)
	
	*Anti
	sum rec_anti if know_anti & sp_type!=1
	local know_do_gap_anti = r(mean)
	
	sum know_anti 
	
	local know_do_change_anti = -`know_do_gap_anti' *r(mean)
	
	*adjusted numbers
	foreach stat in  know_change_ors know_do_change_ors know_change_anti know_do_change_anti{
		local `stat' = string(``stat'', "%10.3f")  
	}
	
	mata: tab_ors = ( tab_ors \  "`i'" , "`know_change_ors'" , "`know_do_change_ors'" )
	mata: tab_anti = ( tab_anti \ "`i'" , "`know_change_anti'" , "`know_do_change_anti'" )
	
	restore
}

mmat2tex tab_ors using "tables/eliminating_barriers_ors.tex", replace 
mmat2tex tab_anti using "tables/eliminating_barriers_anti.tex", replace 
